<%--
  Created by IntelliJ IDEA.
  User: mr.circle
  Date: 2017/7/27
  Time: 11:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>请假统计</title>
    <link rel="stylesheet" href="/css/foot/index.css">

    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" href="/css/base.css">
    <script type="text/javascript" src="../js/news/jquery-1.9.1.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>

</head>
<style>
    .Query,.outport{
        margin-top: 16px;
        background: #00a0e9;
        margin-left: 10px;
        padding:5px 10px;
        border-radius: 4px;
        color: #fff;
        cursor: pointer;
    }
    .deleteSc{
        white-space:nowrap;
    }

</style>
<body>
<div class="headTop">
    <div class="headImg">
        <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_logProfile.png" alt="">
    </div>
    <div class="divTitle">
        请假统计
    </div>
</div>
<div style="margin: 0 auto;margin-top: 46px;height: 60px;width: 97%;" class="navigation clearfix">

    <button  type="button" class="Query" onclick="query();">查询</button>
    <button  type="button" class="outport" >导出</button>
    <div class="left" style="float:  left;">
        <div class="nav_date">
            请假开始时间:
        </div>
        <input class="button1" id="startTime" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" style="height: 28px!important;margin-top: 18px!important;float: left;">

        <div class="nav_date">
            请假结束时间:
        </div>
        <input class="button1" id="endTime" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" style="height: 28px!important;margin-top: 18px!important;float: left;">
    </div>
    <label class="fl clearfix" style="margin-top: 16px;margin-left: 10px;">
        <span class="f1" style="margin-top: 7px;color: #666;font-size: 15px;display: inline-block" ><fmt:message code="foot.th.chooseType" />：</span>
        <select class="app" style="margin-top: -5px;">
            <option value="0">全部类型</option>
            <option value="1">班主任</option>
            <option value="2">非班主任</option>
            <option value="3">总务后勤</option>
            <option value="4">行政</option>

        </select>
    </label>
</div>


<div class="pagediv" style="margin: 0 auto;width: 97%;">
    <table>
        <thead>
        <tr>
            <th>请假流水号</th>
            <th>姓名</th>
            <th>教研组</th>
            <th>年级组</th>
            <th>请假类型</th>
            <th>请假开始时间</th>
            <th>请假结束时间</th>
            <th>共计天数</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<div id="dbgz_page" class="M-box3 fr" style="margin-right: 24px;">

</div>
<script>
    //格式化时间
    function   formatDate(now)   {
        if(now!=''&& now!=undefined){
            var   year=now.getFullYear();
            var   month=now.getMonth()+1 ;
            var Month = month >= 10 ? month:'0'+month;
            var   date=now.getDate();
            var   hour=now.getHours();
            var   minute=now.getMinutes();
            var   second=now.getSeconds();
            return  year+"-"+Month;
        }else{
            return "";
        }
    }
    $('#startTime').val(formatDate(new Date())+'-01')
    $('#endTime').val(new Date().Format('yyyy-MM-dd'))

    Date.prototype.format = function(format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                    ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    }

    function check(name){
        if(name == undefined || name == null){
            return ''
        }else{
            return name;
        }
    }




    function getCookie (key) {
        var arr=document.cookie.split('; '); //多个cookie之间是用;+空格连接的
        for (var i = 0; i < arr.length; i++) {
            var arr2=arr[i].split('=');
            if(arr2[0]==key){
                return arr2[1];
            }
        }
        return false;//如果函数没有返回值，得到的结果是undefined
    }

    var ajaxPage={
        data:{
            DATA_162:$('#startTime').val(),
            DATA_163:$('#endTime').val(),
            type:$('.app option:selected').val(),
            page:1,
            pageSize:10,
            useFlag:true
        },
        page:function () {
            var me=this;
            var type = $('.app').val();
            $.get('/manage/leaveStatisticsQuery',me.data,function (json) {
                var str='';
                var data=json.obj
//                console.log(data)
                if(type == 0){
                    for(var i=(me.data.page-1);i<(me.data.page*me.data.pageSize);i++){
                        str+='<tr>'+
                            '<td>'+check(data[i].rUN_ID)+'</td>' +
                            '<td>'+check(data[i].dATA_154)+'</td>' +
                            '<td>'+check(data[i].dATA_164)+'</td>' +
                            '<td>'+function(){
                                if(type == '1'){
                                    return check(data[i].dATA_174)
                                }else if(type == '2'){
                                    return check(data[i].dATA_173)
                                }else if(type == '3'){
                                    return check(null)
                                }else if(type == '0') {
                                    return data[i].dATA_173||data[i].dATA_174||data[i].dATA_169||""
                                }else {
                                    return check(data[i].dATA_169)
                                }
                            }()+'</td>' +
                            '<td>'+check(data[i].dATA_95)+'</td>' +
                            '<td>'+check(data[i].dATA_162)+'</td>' +
                            '<td>'+check(data[i].dATA_163)+'</td>' +
                            '<td>'+check(data[i].dATA_17)+'</td>' +
                            '</tr>'
                    }
                    $('.pagediv table tbody').html(str)
                    me.pageTwo(json.totleNum,me.data.pageSize,me.data.page,type,data)
                }else{
                    for(var i=0;i<data.length;i++){
                        str+='<tr>'+
                            '<td>'+check(data[i].rUN_ID)+'</td>' +
                            '<td>'+check(data[i].dATA_154)+'</td>' +
                            '<td>'+check(data[i].dATA_164)+'</td>' +
                            '<td>'+function(){
                                if(type == '1'){
                                    return check(data[i].dATA_174)
                                }else if(type == '2'){
                                    return check(data[i].dATA_173)
                                }else if(type == '3'){
                                    return check(null)
                                }else if(type == '0') {
                                    return data[i].dATA_173||data[i].dATA_174||data[i].dATA_169||""
                                }else {
                                    return check(data[i].dATA_169)
                                }
                            }()+'</td>' +
                            '<td>'+check(data[i].dATA_95)+'</td>' +
                            '<td>'+check(data[i].dATA_162)+'</td>' +
                            '<td>'+check(data[i].dATA_163)+'</td>' +
                            '<td>'+check(data[i].dATA_17)+'</td>' +
                            '</tr>'
                    }
                    $('.pagediv table tbody').html(str)
                    me.pageTwo(json.totleNum,me.data.pageSize,me.data.page,type)
                }


            },'json')
        },
        pageTwo:function (totalData, pageSize,indexs,type,data) {
            var mes=this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage:'',
                endPage: '',
                current:indexs||1,
                callback: function (index) {

                    mes.data.page=index.getCurrent();
                    if(type != 0){
                        mes.page();
                    }else{
                        var str="";
                        var index = index.getCurrent();
                        for(var i=(index-1)*pageSize;i<(index*pageSize);i++){
                            if(data[i] != undefined){
                                str+='<tr>'+
                                    '<td>'+check(data[i].rUN_ID)+'</td>' +
                                    '<td>'+check(data[i].dATA_154)+'</td>' +
                                    '<td>'+check(data[i].dATA_164)+'</td>' +
                                    '<td>'+function(){
                                        if(type == '1'){
                                            return check(data[i].dATA_174)
                                        }else if(type == '2'){
                                            return check(data[i].dATA_173)
                                        }else if(type == '3'){
                                            return check(null)
                                        }else if(type == '0') {
                                            return data[i].dATA_173||data[i].dATA_174||data[i].dATA_169||""
                                        }else {
                                            return check(data[i].dATA_169)
                                        }
                                    }()+'</td>' +
                                    '<td>'+check(data[i].dATA_95)+'</td>' +
                                    '<td>'+check(data[i].dATA_162)+'</td>' +
                                    '<td>'+check(data[i].dATA_163)+'</td>' +
                                    '<td>'+check(data[i].dATA_17)+'</td>' +
                                    '</tr>'
                            }
                            $('.pagediv table tbody').html(str)
                            }

                    }
                }
            });
        },
        pageThree:function(data,page,totleNum){

        }

    }
    $('#dbgz_page a').click(function(){
        var page = $(this).attr('data-page');
        console.log(page)
        var str=""
        for(var i=(page-1)*ajaxPage.data.pageSize;i<(page*ajaxPage.data.pageSize);i++){
            str+='<tr>'+
                '<td>'+check(data[i].rUN_ID)+'</td>' +
                '<td>'+check(data[i].dATA_154)+'</td>' +
                '<td>'+check(data[i].dATA_164)+'</td>' +
                '<td>'+function(){
                    if(type == '1'){
                        return check(data[i].dATA_174)
                    }else if(type == '2'){
                        return check(data[i].dATA_173)
                    }else if(type == '3'){
                        return check(null)
                    }else if(type == '0') {
                        return data[i].dATA_173||data[i].dATA_174||data[i].dATA_169||""
                    }else {
                        return check(data[i].dATA_169)
                    }
                }()+'</td>' +
                '<td>'+check(data[i].dATA_95)+'</td>' +
                '<td>'+check(data[i].dATA_162)+'</td>' +
                '<td>'+check(data[i].dATA_163)+'</td>' +
                '<td>'+check(data[i].dATA_17)+'</td>' +
                '</tr>'
        }
        $('.pagediv table tbody').html(str)
        me.pageTwo(json.totleNum,me.data.pageSize,me.data.page,type)
    })
//    导出
    $('.outport').click(function(){
        var startTime = $('#startTime').val();
        var endTime = $('#endTime').val();
        var type = $('.app option:selected').val();
//        console.log(type)
        window.location.href='/manage/leaveStatisticsExport?DATA_162='+startTime+'&DATA_163='+endTime+'&type='+type
    })


    function query(){
        ajaxPage.data.page=1;
        ajaxPage.data.type=$('.app').val();
        ajaxPage.data.DATA_162=$('#startTime').val();
        ajaxPage.data.DATA_163=$('#endTime').val();
        ajaxPage.page()
    }
    var start = {
        elem: '#sendTime',
        format: 'YYYY-MM-DD',
        istime: true,
        istoday: false,

        //回调函数
    };
    $(function(){
        //新建分类接口
        ajaxPage.data.page=1;
        ajaxPage.page()
    })
</script>
</body>
</html>
